package com.dianping.cat.configuration.business.transform;

import com.dianping.cat.configuration.business.entity.BusinessItemConfig;
import com.dianping.cat.configuration.business.entity.BusinessReportConfig;
import com.dianping.cat.configuration.business.entity.CustomConfig;
import org.xml.sax.Attributes;










public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public BusinessItemConfig buildBusinessItemConfig(Attributes attributes) {
/*  22 */     String id = attributes.getValue("id");
/*  23 */     String viewOrder = attributes.getValue("view-order");
    String title = attributes.getValue("title");
    String showCount = attributes.getValue("show-count");
/*  26 */     String showAvg = attributes.getValue("show-avg");
/*  27 */     String showSum = attributes.getValue("show-sum");
/*  28 */     String alarm = attributes.getValue("alarm");
    String privilege = attributes.getValue("privilege");
/*  30 */     BusinessItemConfig businessItemConfig = new BusinessItemConfig(id);

    if (viewOrder != null) {
/*  33 */       businessItemConfig.setViewOrder(((Double)convert(Double.class, viewOrder, Double.valueOf(0.0D))).doubleValue());
    }

    if (title != null) {
/*  37 */       businessItemConfig.setTitle(title);
    }

/*  40 */     if (showCount != null) {
/*  41 */       businessItemConfig.setShowCount(((Boolean)convert(Boolean.class, showCount, Boolean.valueOf(false))).booleanValue());
    }

/*  44 */     if (showAvg != null) {
/*  45 */       businessItemConfig.setShowAvg(((Boolean)convert(Boolean.class, showAvg, Boolean.valueOf(false))).booleanValue());
    }

/*  48 */     if (showSum != null) {
/*  49 */       businessItemConfig.setShowSum(((Boolean)convert(Boolean.class, showSum, Boolean.valueOf(false))).booleanValue());
    }

/*  52 */     if (alarm != null) {
/*  53 */       businessItemConfig.setAlarm(((Boolean)convert(Boolean.class, alarm, Boolean.valueOf(false))).booleanValue());
    }

/*  56 */     if (privilege != null) {
/*  57 */       businessItemConfig.setPrivilege(((Boolean)convert(Boolean.class, privilege, Boolean.valueOf(false))).booleanValue());
    }

/*  60 */     return businessItemConfig;
  }


  public BusinessReportConfig buildBusinessReportConfig(Attributes attributes) {
/*  65 */     String id = attributes.getValue("id");
/*  66 */     BusinessReportConfig businessReportConfig = new BusinessReportConfig();

/*  68 */     if (id != null) {
/*  69 */       businessReportConfig.setId(id);
    }

/*  72 */     return businessReportConfig;
  }


  public CustomConfig buildCustomConfig(Attributes attributes) {
/*  77 */     String id = attributes.getValue("id");
    String viewOrder = attributes.getValue("view-order");
/*  79 */     String title = attributes.getValue("title");
/*  80 */     String alarm = attributes.getValue("alarm");
/*  81 */     String privilege = attributes.getValue("privilege");
/*  82 */     CustomConfig customConfig = new CustomConfig(id);

/*  84 */     if (viewOrder != null) {
/*  85 */       customConfig.setViewOrder(((Double)convert(Double.class, viewOrder, Double.valueOf(0.0D))).doubleValue());
    }

/*  88 */     if (title != null) {
/*  89 */       customConfig.setTitle(title);
    }

/*  92 */     if (alarm != null) {
/*  93 */       customConfig.setAlarm(((Boolean)convert(Boolean.class, alarm, Boolean.valueOf(false))).booleanValue());
    }

/*  96 */     if (privilege != null) {
/*  97 */       customConfig.setPrivilege(((Boolean)convert(Boolean.class, privilege, Boolean.valueOf(false))).booleanValue());
    }

/* 100 */     return customConfig;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 105 */     if (value == null || value.length() == 0) {
/* 106 */       return defaultValue;
    }

/* 109 */     if (type == Boolean.class || type == boolean.class)
/* 110 */       return (T)Boolean.valueOf(value); 
/* 111 */     if (type == Integer.class || type == int.class)
/* 112 */       return (T)Integer.valueOf(value); 
/* 113 */     if (type == Long.class || type == long.class)
/* 114 */       return (T)Long.valueOf(value); 
/* 115 */     if (type == Short.class || type == short.class)
/* 116 */       return (T)Short.valueOf(value); 
/* 117 */     if (type == Float.class || type == float.class)
/* 118 */       return (T)Float.valueOf(value); 
/* 119 */     if (type == Double.class || type == double.class)
/* 120 */       return (T)Double.valueOf(value); 
/* 121 */     if (type == Byte.class || type == byte.class)
/* 122 */       return (T)Byte.valueOf(value); 
/* 123 */     if (type == Character.class || type == char.class) {
/* 124 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 126 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-core-3.0.0.jar!/com/dianping/cat/configuration/business/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */